<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <title>跨浏览器的事件实用工具</title>
</head>
<body>
<script>
    var evt = {
        addListener: function (obj, type, fn) {
            if (obj.addEventListener) {
                obj.addEventListener(type, fn);
            } else {
                obj.attachEvent('on' + type, fn);
            }
        },

        removeLisetener: function (obj, type, fn) {
            if (obj.removeEventListener) {
                obj.removeEventListener(type, fn);
            } else {
                obj.detachEvent('on' + type, fn);
            }
        },

        getTarget: function (e) {
            if (e.target) {
                return e.target;
            }
            return e.srcElement;
        },

        preventDefault: function (e) {
            if (e.preventDefault) {
                e.preventDefault();
            } else {
                e.returnValue = false;
            }
        }
    }
</script>
<a id="some-link">Click Me</a>
<script>
    var link = document.getElementById('some-link');
    function linkClick(e) {
        alert('This is is going nowhere');
        evt.preventDefault(e);
    }
    evt.addListener(link, 'click', linkClick);
</script>
</body>
</html>